package cn.ecnu;


import cn.ecnu.constant.ResponseStatus;
import cn.ecnu.entity.Address;
import cn.ecnu.entity.Car;
import cn.ecnu.entity.Employee;
import cn.ecnu.mapper.AddressMapper;
import cn.ecnu.mapper.EmployeeMapper;
import cn.ecnu.service.CarService;
import com.github.javafaker.Faker;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.Locale;

@SpringBootTest
public class MainApplication {

    @Resource
    EmployeeMapper mapper;

    @Resource
    CarService carService;

    @Resource
    AddressMapper addressMapper;

    @Test
    void createForAddress() {
        String[] uid = {"123", "456", "789"};
        Faker faker = new Faker(new Locale("zh-CN"));
        Address address = new Address();
        for (int i = 0; i < 20; i++) {
            address.setAddress(faker.address().city().concat("市").concat("xxxxxxxxxxxxxxxxxx"));
            address.setName(faker.name().name());
            address.setPhone(faker.phoneNumber().cellPhone());
            address.setUid(uid[faker.random().nextInt(0, 2)]);
            addressMapper.insert(address);
        }
    }

    @Test
    void createForEmployee() {
        String[] positions = {"快递员", "运输员", "揽件员"};
        Faker faker = new Faker(new Locale("zh-CN"));
        Employee employee = new Employee();
        for (int i = 0; i < 40; i++) {
            employee.setId(ResponseStatus.uuidGenerator());
            employee.setLocation(faker.address().city().concat("市"));
            employee.setName(faker.name().name());
            employee.setPhone(faker.phoneNumber().phoneNumber());
            employee.setTotalWorkingAmount(faker.random().nextInt(0, 50));
            employee.setPosition(positions[faker.random().nextInt(0, 2)]);
            mapper.insert(employee);
        }
    }


    @Test
    void createForCar() {
        Faker faker = new Faker(new Locale("zh-CN"));
        Car car = new Car();

        for (int i = 0; i < 80; i++) {
            car.setId(ResponseStatus.uuidGenerator());
            car.setFree(faker.random().nextInt(0, 1));
            car.setLicense(faker.dragonBall().character());
            car.setLocation(faker.address().city().concat("市"));
            carService.save(car);
        }


    }

    @Test
    void test() {
        Faker faker = new Faker(new Locale("zh-CN"));
        System.out.println(faker.address().cityName().concat("市"));

    }

}
